<%--
  Created by IntelliJ IDEA.
  User: 16128
  Date: 2020/8/10
  Time: 17:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>update</title>
</head>
<body>
    <form action="account/update" method="post">
        username:<input name="username" disabled="true" value="ayun"><br>
        oldPassword:<input name="oldPassword"><br>
        newPassword:<input name="newPassword"><br>
        <select name="status" disabled="true">
            <option value="admin" selected="true">admin</option>
            <option value="user">user</option>
            <option value="doctor">doctor</option>
        </select>
        <input type="submit" value="submit">
    </form>

    <script src="jquery-3.5.1.min.js"></script>
    <script>
        $("input[type='submit']").click(function (e) {
            e.preventDefault()
            console.log('click')

            var account = {
                username:$("input[name='username']").val(),
                oldPassword:$("input[name='oldPassword']").val(),
                newPassword:$("input[name='newPassword']").val(),
                status:$("select").val()
            }
            console.log(JSON.stringify(account))

            var data = "username="+$("input[name='username']").val()
            data += "&oldPassword="+$("input[name='oldPassword']").val()
            data += "&newPassword="+$("input[name='newPassword']").val()
            data += "&status="+$("select").val()
            console.log(data)


            $.ajax({
                url:"account/update",
                type:"POST",
                data:data,
                success:function (res) {
                    console.log('result: '+res)
                }
            })

            return false
        })
    </script>
</body>
</html>
